package demo3;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;



public class demo6Servlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        // 处理GET请求的业务逻辑代码
        resp.setContentType("text/html; charset=UTF-8");
        resp.getWriter().println("xml--servlet");
        String servletName = this.getServletConfig().getServletName();
        resp.getWriter().println("servletName="+servletName);
        resp.getWriter().println("<br>");
        String name = this.getServletConfig().getInitParameter("name");
        resp.getWriter().println("demo6Servlet的参数name="+name);
        resp.getWriter().println("<br>");

        String id = this.getServletContext().getInitParameter("id");
        resp.getWriter().println("整个项目参数 id="+id);

        resp.getWriter().println("<br>");
        this.getServletContext().setAttribute("age","12");
        resp.getWriter().println("ServletContext中age="+this.getServletContext().getAttribute("age"));
    }
}

